package com.wlj.security.core.authorize;

import com.wlj.security.core.properties.SecurityConstants;
import com.wlj.security.core.properties.WljSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component;

@Component
@Order(Integer.MIN_VALUE)
public class WljAuthorizeConfigProvider implements AuthorizeConfigProvider{

    @Autowired
    private WljSecurityProperties wljSecurityProperties;

    /**
     * 匹配上的url无需认证
     * @param config
     */
    @Override
    public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
        config.antMatchers(  SecurityConstants.DEFAULT_UNAUTHENTICATION_URL,
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_MOBILE,
                SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM,
                wljSecurityProperties.getBrowser().getLoginPage(),
                SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX+"/*",
                wljSecurityProperties.getBrowser().getSignUpUrl(),
                wljSecurityProperties.getBrowser().getSession().getSessionInvalidUrl()+".html")
                .permitAll();
    }
}
